package top.jojoace.JPA.service;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import top.jojoace.JPA.repository.SqlRepository;
import top.jojoace.JPA.model_DDL.SqlModel.SqlModel;

import java.io.DataInput;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class SqlServiceImpl{
    private final SqlRepository sqlRepository;

    private final ObjectMapper objectMapper;

    @SneakyThrows
    public Map<String,Object> saveSqlModel(SqlModel sqlModel){
        SqlModel s = this.sqlRepository.save(sqlModel);
        String string = objectMapper.writeValueAsString(s);
        return objectMapper.readValue(string, new TypeReference<Map<String,Object>>(){});
    }
}
